package pl.edu.pw.elka.jtrzasko.proz.warcaby.messages;

import java.util.HashMap;

import pl.edu.pw.elka.jtrzasko.proz.warcaby.actions.Action;
import pl.edu.pw.elka.jtrzasko.proz.warcaby.actions.client.ClientAction;
import pl.edu.pw.elka.jtrzasko.proz.warcaby.actions.server.ServerAction;
import pl.edu.pw.elka.jtrzasko.proz.warcaby.controller.ServerController;
import pl.edu.pw.elka.jtrzasko.proz.warcaby.messages.client.ClientMessage;
import pl.edu.pw.elka.jtrzasko.proz.warcaby.messages.server.ServerMessage;
import pl.edu.pw.elka.jtrzasko.proz.warcaby.view.ClientView;

public class MessageFactory {

	private static HashMap<String,Action> registeredMessages = new HashMap<String,Action>();

	public static void registerMessage (String messageName, Action action)
	{
		registeredMessages.put(messageName, action);
	}

	public static void runClientAction(ClientMessage message, ServerController serverController)
	{
		((ClientAction)registeredMessages.get(message.getClass().getSimpleName())).run(serverController, message);
	}	
	public static void runServerAction(ServerMessage message, ClientView clientView)
	{
		((ServerAction)registeredMessages.get(message.getClass().getSimpleName())).run(clientView, message);
	}	
	

}
